<?php

/**
 * 模板中导入区块，可缓存
 * @method import
 * @param  [type]  $blockName [块名]
 * @param  integer $cacheTime [缓存时间;0,不缓存]
 * @param  string $addKey [缓存附加key，一对多使用]
 * @return [type]             [description]
 * @author NewFuture
 */
function import($blockName, $cacheTime = 0, $arguments = array())
{

	if ($cacheTime === 0)
	{
		/*不缓存，直接导入*/
		return include HTML_TPL . $blockName . '.php';
	}
	else
	{   
		$add   = (empty($arguments)) ? '' : '_' . md5(serialize($arguments));
		$key   = 'block_' . $blockName . $add;
		$cache = cache::get($key);
		if ($cache)
		{
			/*直接输出缓存*/
			echo $cache;
		}
		else
		{
			/*显示到页面上的内容，先写入缓存，再输出*/
			ob_start();
			include HTML_TPL . $blockName . '.php';
			$cache = ob_get_contents();
			//缓存
			cache::set($key, $cache, $cacheTime);
			ob_end_flush();
		}
	}
}

function importHeader($arguments = array())
{
	import('header', 600, $arguments);
}
function importFooter($arguments = array())
{
	import('footer', 600, $arguments);
}

